#include <iostream>
#include <stdexcept>
using namespace std;

class InputException {	// Usually inherit from an exception class
	string err;
public:
	InputException(string s) { 
		err = s;
		cerr << "Constructor called" << endl;
	}
	~InputException() {
		cerr << "Destructor called" << endl;
	}
	void print(void) const {
		cerr << err << endl;
	}
};

void g(int i)
{
	if (i < 0) {
		//InputException *p = new InputException("Pointer");
		throw InputException("Input is less than zero");
		//throw p;
	}
	if (i > 100)
		//throw InputException("Input is larger than 100");
		throw i;
	int j;
	j = 100 / i;
	cout << j << endl;
}

void f(int j)
{
	cout << "Enter f" << endl;
	g(j);
	cout << "Exit f" << endl;
}


int main(int argc, char **argv)
{
	if (argc < 2) {
		cerr << "usage: " << argv[0] << " N" << endl;
		return 1;
	}

	// stack unwind
	try {
		cout << atoi(argv[1]) << endl;
		f(atoi(argv[1]));
	}
	//catch (const InputException& e) {	// What if "InputException *e" ?
	catch (...) { // catch all kinds of exceptions
		//e.print();
		cout << "Unknown Error" << endl;
		//cout << "Int err" << i << endl;
		//e->print();
		return 1;
	}

	return 0;
}
